package com.haitaoit.chengquan.module.center_service.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.home.model.RecruitListModel;
import com.haitaoit.chengquan.view.CircleImageView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class ServiceRecruitAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<RecruitListModel> list;

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public ServiceRecruitAdapter(Context context) {
        this.context = context;
    }

    public List<RecruitListModel> getList() {
        return list;
    }

    public void setList(List<RecruitListModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.service_recruit_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.recruit_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ServiceRecruitAdapter.this.backCall.deal(R.id.recruit_ll, position);
            }
        });

        holder.recruit_detele.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ServiceRecruitAdapter.this.backCall.deal(R.id.recruit_detele, position);
            }
        });

        ImageLoader.getInstance().displayImage(list.get(position).getImg_ur(), holder.center_img);
        holder.recruit_title.setText(list.get(position).getTitle());
        holder.recruit_time.setText(list.get(position).getAddtime());
        holder.companyname.setText(list.get(position).getCompanyname());
        holder.post_salary.setText(list.get(position).getPost_salary());
        holder.recruit_area.setText(list.get(position).getArea());
        holder.experience_requirements.setText("工作经验：" + list.get(position).getExperience_requirements());
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.recruit_ll)
        LinearLayout recruit_ll;
        @ViewInject(R.id.recruit_detele)
        LinearLayout recruit_detele;
        @ViewInject(R.id.center_img)
        CircleImageView center_img;
        @ViewInject(R.id.recruit_title)
        TextView recruit_title;
        @ViewInject(R.id.recruit_time)
        TextView recruit_time;
        @ViewInject(R.id.companyname)
        TextView companyname;
        @ViewInject(R.id.post_salary)
        TextView post_salary;
        @ViewInject(R.id.recruit_area)
        TextView recruit_area;
        @ViewInject(R.id.experience_requirements)
        TextView experience_requirements;
    }
}
